Repository navigation
feat(service-knowledge): build a never-built source after boot; os knowledge rebuild and status - #37439
Conversation
…owledge rebuild and status After boot, KnowledgeServicePlugin reads what each object source's adapter holds against the index fingerprint and recipe hash (ADR-0161 K7, "What starts a rebuild") and builds, in the background and one at a time, every source that is unbuilt, under another fingerprint or under another recipe hash. A build runs under the cluster service's lock so one node builds a source. The knowledge settings namespace gains the administrator's rebuild and index_status actions; os knowledge rebuild and os knowledge status call them. Progress and results are logged, and the docs state the cost. Claude-Session: https://claude.ai/code/session_01JQwxbXkQAmjg7Hf74xDKA6 Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 2 package(s): 14 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 4 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 43 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 67bf557f73711286ffb93c60c7019518887a5433 && git checkout 67bf557f73711286ffb93c60c7019518887a5433
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin a46efa8c625f2b43d4aa1aa1044eb702667ba07d 1061045e49d4f7c5ed116c87cfe010d232f78614 && git checkout -B drift-repro a46efa8c625f2b43d4aa1aa1044eb702667ba07d && git merge --no-ff 1061045e49d4f7c5ed116c87cfe010d232f78614
node scripts/docs-audit/affected-docs.mjs --json a46efa8c625f2b43d4aa1aa1044eb702667ba07d
|
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract-review-claim: session_01Utp6CYtTDvfPQDzMbZnN5X · head 3681410 · 2026-11-26T06:22Z The seat runs the at-tier contract review of this head through an isolated sub-agent; L1 is the seat's own. |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract reviewServed-tier: PR #37439 for card #37099 (epic #37000). Face: declaration ( Check-runs on the head: every run concluded ① Derived judgmentsCard acceptance
The build lock's lease against long builds (previous seat's point 1)
Admin-only rebuild and status on every door (previous seat's point 2)
Per-node build records against the card (previous seat's point 3)
The field gate's
Docs
Boot-time build
Settings contribution
CLI
② Semver level
③ Boundary flags
No must-fix. S1 to S6 are should-fix: S4, S5 and S6 are small enough to ride the next push; S1, S2 and S3 can be follow-up rows if the seat prefers. Implemented-by: VERDICT: PASS |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X 席位核对Head-sha:
|
…s; docs and CLI follow-ups - The rebuild and index_status settings actions are refused 403 SETTINGS_FORBIDDEN to a caller without manage_platform_settings, through the real settings action door, naming no source and reaching no handler. - The cost callout says the default memory adapter is empty after every restart (each boot re-embeds the whole source on each node), and that one builder per source needs a shared cluster lock driver. - os knowledge rebuild --no-wait says it reports no outcome. - buildSourcesAtBoot lists the sources inside its try, and its background call carries a catch. - A first build that opened a generation and never completed reads as nothing built, not as another fingerprint. Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
…ry is answered 401 Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
…adapter rebuilds at every boot; --no-wait reports no outcome Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract-review-claim: session_01Utp6CYtTDvfPQDzMbZnN5X · head 1061045 · 2026-11-26T07:25Z |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract reviewServed-tier: Delta review of PR #37439 for card #37099 (epic #37000), on top of the record for head Check-runs on the head: 42 ① Derived judgmentsFindings of the previous record
New in the delta
② Semver level
③ Boundary flags
No must-fix and no open should-fix on this head. S1 and S2 are carried by open cards. One landing condition: the newer Implemented-by: VERDICT: PASS |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X 席位核对Head-sha:
|
|
repo:objectstack#5 · os-bill · session_01Utp6Cb4BAjgQ43tqy1DvVJ Landing · 2026-11-26T07:30Z · zone ai-37000
State change: ready for review + auto-merge (merge queue). #37099 closes on merge; close-out follows. knowledge-rag.mdx siblings (#37442, #37004) merge main after this lands. |
Requested by Warren · project thread
Fixes #37099
Clause-②: yes
Metadata-protocol: none
维护者速读
What changes
First build after boot (
@objectstack/service-knowledge)KnowledgeService.readIndexState(source)reads ADR-0161 K7's table for one source: the adapter holds nothing, a different fingerprint, a different recipe hash, no recipe hash, current, or (an adapter withoutindexStatus) whetherlistDocumentslists anything. Each reading says whether a build is due.KnowledgeService.buildSourcesAtBoot()runs from the plugin'skernel:bootstrappedhook, after the embedder is provided, without holding up the boot. It walks the sources one at a time and builds each one a build is due for. A source withrefresh.onRecordChange: false(an external indexer owns it) is skipped. A state it cannot read, or an adapter that cannot say, is logged at warn and left alone; the operator rebuild is the way for those.rebuildSourcetakes the cluster lockknowledge:build:SOURCE(ILock, 60 s lease renewed every 20 s,waitMs: 0). A node that finds the lock held recordsnot-runand builds nothing. A node that gets the lock re-reads the state first, so a node arriving after another finished builds nothing either. If the lock service errors, no build starts and the node warns. Without aclusterservice (single process) the build runs without a lock.wherematches is read, and its content fields are sent to the embedding provider, which bills for them), progress at most every 10 s, and its totals at the end (info) or why it did not finish (warn).buildAtBoot(defaulttrue).falseturns the boot pass off; the operator rebuild still works.Operator rebuild
knowledgesettings namespace, besidetest:rebuild({ source }) starts a build and answers at once;index_status({ source? }) answers each source's index reading and the last build record on this node, with its progress. Both go through the settings action door, so both needmanage_platform_settings. A second rebuild of a source already building on this node is refused.os knowledge rebuild SOURCEstarts one and follows it to its end by pollingindex_status(--no-waitto return at once,--interval). It exits 1 when the build failed or did not run, or when the answer comes from a node that is not running this build.os knowledge status [source]prints each source, its index state and its last build on the node that answered.Docs:
content/docs/ai/knowledge-rag.mdxgains "The first build, and rebuilding a source": the K7 table, what one build costs (a warn callout), how to turn the boot pass off, and the two commands.Rework round (seat L1 REWORK, contract record PASS with should-fix findings)
knowledge-settings-contribution.test.tsgains "the rebuild and index_status actions are administrator-only, at the HTTP door": a realLiteKernelwithKnowledgeServicePluginandSettingsServicePlugin, driven throughregisterSettingsRoutesand the realSettingsService.runAction. A signed-in caller withoutmanage_platform_settings(an organization member holdingsetup.read/setup.write, or one with no capability) gets403 SETTINGS_FORBIDDENforrebuildandindex_status; an unauthenticated one gets401 UNAUTHENTICATED. No refusal names the source (id or label), and no handler method on the service (listSources,getSource,readIndexState,rebuildSource,buildRecord) is called. A control shows the same door lets an administrator through and then names the source, and the in-processrunActionwith an enforced member context rejects withSETTINGS_FORBIDDEN. The gate itself is unchanged; it still lives in theknowledgemanifest'swritePermission, and relaxing it now turns these pins red (ablation below).content/docs/ai/knowledge-rag.mdxnow says the defaultmemoryadapter holds nothing after a restart, so with it every boot is a first build that re-embeds the whole source on every node; and that "only one node builds a source" holds only with a shared cluster lock driver, because the defaultmemorycluster driver's lock is a per-process mutex. The paragraph above the callout now qualifies its "only one builds" sentence the same way and links the cluster page. The changeset says both.content/docs/deployment/cli.mdxgains a### Knowledgesection after### MCP, in the shape of the other command groups (overview table, one####per command with examples, a flag table):os knowledge statusandos knowledge rebuild, their exit codes, the admin-only door, and the per-node build record.os knowledge rebuild --no-waitnow prints that it reports no outcome and points atos knowledge status; the flag help and the CLI reference say so), N3 (buildSourcesAtBootlists the sources inside atryand resolves with a warn when it cannot; the plugin'svoidcall carries a.catch), N5 (an adapter reporting{ building: true }with no active fingerprint, a first build that never completed, now readsnothingwith its own sentence instead ofnew-fingerprint). N1 (the optionalprotocol/knowledge.mdxpointer) stays an accepted deviation.os knowledge rebuildcan exit 1 on a poll that lands elsewhere) is service-knowledge: os knowledge rebuild and status give the right answer behind a load balancer #37466. S5 (retiring the field gate'stitlearm) is service-knowledge: retire the field gate's title arm once a source's index is proven built under the current recipe #37467.Why
A source that was never built had an empty index until each of its rows was written again; search found nothing and nothing said why. After an embedder or recipe change the index stayed stale the same way. ADR-0161 K7 says what starts a rebuild; nothing ran it.
Tests
packages/services/service-knowledge/src/__tests__/knowledge-build.test.ts(20 tests): everyreadIndexStatereading; a fresh source is built at boot and search finds its rows; a built source is not rebuilt; two nodes sharing one lock build once (onedone, onenot-run, lock released); a node arriving late re-reads and builds nothing; a lock error starts nothing and warns;onRecordChange: falseis skipped; a failed build is logged at warn and stays due; therebuildandindex_statusactions (progress, result, an operator rebuild skipping unchanged documents, a running build refused, bad payloads refused); the plugin'skernel:bootstrappedpass andbuildAtBoot: false.packages/cli/src/commands/knowledge/knowledge.test.ts(7 tests): both commands against bodies written bysendOk/sendError: the route and payload, following a build to its end, exit 1 on a failed build, on a server refusal, and on an answer from a node not running this build;--no-wait.lock.acquirewith an always-granted handle fails the two-node and lock-unreachable tests.knowledge-settings-contribution.test.ts+10 tests (the admin-gate pins above);knowledge-build.test.ts+2 (N3: a listing that throws resolves and warns; N5:{ building: true }readsnothing);knowledge.test.ts: the--no-waitcase now also asserts the line namingos knowledge status(N2).scripts/ablation-replace.mjs(landing proved on disk, restore provedgit diff HEADempty):knowledgemanifest'swritePermissionset tosetup.writein@objectstack/service-settings, package rebuilt (the pins read itsdist/): the four member cases, the admin control and the in-process case turn red (6 failed, 4 passed); restored and rebuilt, 10/10 green, and the built manifest readswritePermission: "manage_platform_settings"again.--no-waittest red. All three green again after restore.Acceptance notes
titlearm of the field gate is not retired here. Per the 11-25 14:55Z comment it can go once a rebuild has run, but it is a security gate and retiring it needs proof per source at search time that the index was built under the current recipe. That is its own row, service-knowledge: retire the field gate's title arm once a source's index is proven built under the current recipe #37467; this PR only makes the rebuild happen.index_statusreports the build the answering node ran. Behind a load balancer,os knowledge statusmay reach a node that is not building;os knowledge rebuildsays so and exits 1 rather than guessing. The index state itself is read from the adapter and is the same on every node. Sharing the record, or letting the CLI fall back to the index state, is service-knowledge: os knowledge rebuild and status give the right answer behind a load balancer #37466.content/docs/deployment/cli.mdxnow lists both commands (S6).content/docs/frontend/cli.mdxis not updated: it is outside this card's file surface.Verification
service-knowledge: 14 test files / 436 tests pass;tsc --noEmitandcheck:test-typecheckpass.eslint --no-inline-configon every changed file passes.tsc --noEmit: not measured locally. This container has no builtdist/for the CLI's workspace dependencies (563 TS2307-family errors, none in a knowledge file); CI owns it.LiteKernels sharing oneMemoryLockover a 250-row source. Boot returned in 9 ms without waiting for the build. Node A:done, 250 indexed; node B:not-run("another node holds the build");beginBuildcalled once; search found rowr0007; the state afterwards readcurrent. A non-adminrunAction('knowledge','rebuild')was refused ("requires the 'manage_platform_settings' capability"); an admin rebuild then showeddonewith 250 skipped. The log carried the cost line.check:skill-examples,check:dual-build-cjs-loads,check:i18n,check:i18n-coverage,check:i18n-walk-parity,check-plugin-teardown-shape --self-test; that script's scan alone exits 0). Those six go to CI.knowledge-rag.mdx, Open runtime: requires: ['knowledge'] mounts the knowledge service, and pgvector on PostgreSQL #37102 alsopackages/cli): clean at push time. The second to land merges main.Rework round readings, head 1061045
service-knowledge(dependency closure rebuilt first,turbo run build --filter='@objectstack/service-knowledge^...', 18/18 tasks):pnpm test14 files / 448 tests pass;typecheck(tsc --noEmitandcheck:test-typecheck, 0 files / 0 errors in the debt ledger) passes.src/commands/knowledge/knowledge.test.ts7/7 pass (unit layer). CLItsc --noEmitnot measured locally, for the reason above; CI'sTypeScript Type Checkowns it.eslint --no-inline-configon the seven changed.tsfiles: exit 0.dispatch-gates.mjs --commands, 122 commands, run on a753df9 with the changeset edit in the tree): 114 exit 0. Not measured here, left to CI: six exit 3, PREREQUISITE NOT MET, the same six the first round named (check-plugin-teardown-shape --self-test, whose positive control is pinned to a commit a shallow clone cannot reach, its scan exits 0;spec check:skill-examples,check:dual-build-cjs-loads,check:i18n,check:i18n-coverage,check:i18n-walk-parity, which read built output this container does not have); two whole-repo scans,check:query-options-erasure(its self-test passed) andcheck:type-check-debt, hit the 300 s per-command limit on the shared box. Re-run on 1061045: the changeset family (check-adr-0087-registration,check-changeset-no-major,check-empty-changeset,check:changeset-fixed),check:nul-bytes,check:doc-anchors,check:cli-command-ids,check:cli-examples-parity, all exit 0.overlap-checkbefore each push: clean againstorigin/main, feat(core): requires knowledge mounts the knowledge service and one vector store #37442, feat(spec)!: form is a metadata type of its own, and the form doors read a form over both types #37422 (sharescontent/docs/deployment/cli.mdx) and chore: version packages (next) #35129. Retire @objectstack/knowledge-ragflow: package, settings option, docs and skill mentions #37004 has no PR open yet.Human Minimum
packages/specholds no runtime logic.pnpm lintpasses.main, one pull request.packages/spectouched: its generated artifacts are regenerated and committed. (not touched)content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.🤖 Generated with Claude Code
https://claude.ai/code/session_01JQwxbXkQAmjg7Hf74xDKA6